package com.jadows.tdog.controller;

import com.jadows.tdog.base.R;
import lombok.Data;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
public class LoginController {

    @PostMapping("/login")
    public R<?> login(@RequestBody LoginBody loginBody) {
        Map<String, Object> mockUser = getMockUser(loginBody);
        return R.ok(mockUser);
    }

    @Data
    public static class LoginBody {
        String username;
        String password;
    }

    Map<String, Object> getMockUser(LoginBody loginBody) {
        Map<String, Object> user = new HashMap<>();
        user.put("username", loginBody.username);
        user.put("nickname", loginBody.username);
        user.put("avatar", "https://img.js.design/assets/img/66162695787029539a75f75f.png#9218f925e28fafe038bcfa56b25b7075");
        user.put("roles", new String[]{"admin"});
        user.put("permissions", new String[]{"*:*:*"});
        user.put("accessToken", "eyJhbGciOiJIUzUxMiJ9.admin");
        user.put("refreshToken", "eyJhbGciOiJIUzUxMiJ9.adminRefresh");
        user.put("expires", "2030/10/30 00:00:00");
        return user;
    }

}
